﻿package component.tree.web.taglib;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import component.tree.util.ConfigUtil;


public class TreeSelectTag extends BaseTag {
	
	private String componentId;
	private String title;
	private String condition;
	private String windowWidth = "500";
	private String windowHeight = "460";
	private String positionId;
	private String btnName;//按钮的名字
	
	//文本框的属性
	private String idName = "";//"selectId";
	private String idValue = "";
	private String viewName = "";//"selectName";
	private String viewValue = "";
	private String viewSize = "20";
	private String viewClass = "";//"input-required-as2";
	
	//树型属性
	private String useBaseIconAble = "true";//是否使用标题图片
	private String useLinesAble = "true";//是否使用虚线连着
	private String useIconsAble = "true";//是否使用图片
	private String selectMoreAble = "false";//是否能够选择多个节点，如果是就用checkbox
	private String selectFolderAble = "true";//是否能够选择目录
	private String loadAllAble = "false";//是否一次性加载还是动态加载
	private String firstShowLevel = "1";//第一次显示几层
	private String targetAble = "false";//是否有链接
	private String searchAble = "true";//树型是否提供搜索功能
	
	private String isShowClearBtn = "true";//树型是否显示"重置"按钮
	private String isShowFirstBtn = "true";//树型是否显示"展开"按钮
	
	public int doStartTag() throws JspException {
		HttpServletRequest request = this.getRequest();
		HttpServletResponse response = this.getResponse();
		String context = this.getContext();

		this.setCache();
		
		StringBuffer sb = new StringBuffer();
		
		this.startScript(sb);
		sb.append("var "+this.id+" = new component.Component('"+context+"','"+this.id+"','"+this.positionId+"','"+this.btnName+"');");
		sb.append("\n");
		
		sb.append(this.id + ".createSelectElement('"+this.idName+"','"+this.idValue+"','"+this.viewName+"','"+this.viewValue+"','"+this.viewSize+"','"+this.viewClass+"');");
		sb.append("\n");
		sb.append(this.id + ".windowWidth="+this.windowWidth+";");
		sb.append("\n");
		sb.append(this.id + ".windowHeight="+this.windowHeight+";");
		sb.append("\n");
		
		//参数开始
		sb.append(this.id + ".paras += '");
		//sb.append("&id="+this.id);
		sb.append("&componentId="+this.componentId);
		sb.append("&title="+this.title);	
		sb.append("';");
		sb.append("\n");
		
		sb.append(this.id + ".paras += '");
		sb.append("&isUseBaseIcon="+this.useBaseIconAble);
		sb.append("&isLoadAll="+this.loadAllAble);
		sb.append("&isSelectMore="+this.selectMoreAble);
		sb.append("&isSelectFolder="+this.selectFolderAble);
		sb.append("&isUseLines="+this.useLinesAble);
		sb.append("&isUseIcons="+this.useIconsAble);
		sb.append("&isSearch="+this.searchAble);
		sb.append("';");
		sb.append("\n");
		
		sb.append(this.id + ".paras += '");
		sb.append("&firstShowLevel="+this.firstShowLevel);
		sb.append("&isShowClearBtn="+this.isShowClearBtn);
		sb.append("&isShowFirstBtn="+this.isShowFirstBtn);
		sb.append("';");
		sb.append("\n");
		//参数结束
		
		this.endScript(sb);
	
		this.print(sb.toString());

		return super.doStartTag();

	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public String getComponentId() {
		return componentId;
	}

	public void setComponentId(String componentId) {
		this.componentId = componentId;
	}

	public String getUseLinesAble() {
		return useLinesAble;
	}

	public void setUseLinesAble(String useLinesAble) {
		this.useLinesAble = useLinesAble;
	}

	public String getUseIconsAble() {
		return useIconsAble;
	}

	public void setUseIconsAble(String useIconsAble) {
		this.useIconsAble = useIconsAble;
	}

	public String getTargetAble() {
		return targetAble;
	}

	public void setTargetAble(String targetAble) {
		this.targetAble = targetAble;
	}

	public String getSelectMoreAble() {
		return selectMoreAble;
	}

	public void setSelectMoreAble(String selectMoreAble) {
		this.selectMoreAble = selectMoreAble;
	}

	public String getSelectFolderAble() {
		return selectFolderAble;
	}

	public void setSelectFolderAble(String selectFolderAble) {
		this.selectFolderAble = selectFolderAble;
	}

	public String getLoadAllAble() {
		return loadAllAble;
	}

	public void setLoadAllAble(String loadAllAble) {
		this.loadAllAble = loadAllAble;
	}

	public String getFirstShowLevel() {
		return firstShowLevel;
	}

	public void setFirstShowLevel(String firstShowLevel) {
		this.firstShowLevel = firstShowLevel;
	}

	public String getUseBaseIconAble() {
		return useBaseIconAble;
	}

	public void setUseBaseIconAble(String useBaseIconAble) {
		this.useBaseIconAble = useBaseIconAble;
	}

	public String getWindowHeight() {
		return windowHeight;
	}

	public void setWindowHeight(String windowHeight) {
		this.windowHeight = windowHeight;
	}

	public String getWindowWidth() {
		return windowWidth;
	}

	public void setWindowWidth(String windowWidth) {
		this.windowWidth = windowWidth;
	}

	public String getPositionId() {
		return positionId;
	}

	public void setPositionId(String positionId) {
		this.positionId = positionId;
	}

	public String getSearchAble() {
		return searchAble;
	}

	public void setSearchAble(String searchAble) {
		this.searchAble = searchAble;
	}

	public String getIdName() {
		return idName;
	}

	public void setIdName(String idName) {
		this.idName = idName;
	}

	public String getIdValue() {
		return idValue;
	}

	public void setIdValue(String idValue) {
		this.idValue = idValue;
	}

	public String getViewName() {
		return viewName;
	}

	public void setViewName(String viewName) {
		this.viewName = viewName;
	}

	public String getViewValue() {
		return viewValue;
	}

	public void setViewValue(String viewValue) {
		this.viewValue = viewValue;
	}

	public String getViewSize() {
		return viewSize;
	}

	public void setViewSize(String viewSize) {
		this.viewSize = viewSize;
	}

	public String getViewClass() {
		return viewClass;
	}

	public void setViewClass(String viewClass) {
		this.viewClass = viewClass;
	}

	public String getIsShowClearBtn() {
		return isShowClearBtn;
	}

	public void setIsShowClearBtn(String isShowClearBtn) {
		this.isShowClearBtn = isShowClearBtn;
	}

	public String getIsShowFirstBtn() {
		return isShowFirstBtn;
	}

	public void setIsShowFirstBtn(String isShowFirstBtn) {
		this.isShowFirstBtn = isShowFirstBtn;
	}

	public String getBtnName() {
		return btnName;
	}

	public void setBtnName(String btnName) {
		this.btnName = btnName;
	}
	
}
